<?php
require_once '../../includes/classes/core.php';
require_once "../../includes/libchart/classes/libchart.php";

$agent		    = $_REQUEST['agent'];
$report_name	= $_REQUEST['report_name'];
$queue	        = $_REQUEST['queuet'];
$start_time     = $_REQUEST['start'];
$end_time 	    = $_REQUEST['end'];
$start          = $start_time;
$end            = $end_time;

$day = (strtotime($end_time)) -  (strtotime($start_time));
$day_format = ($day / (60*60*24)) + 1;
// ----------------------------------
{
    $row_done_blank = mysql_fetch_assoc(mysql_query("	SELECT COUNT(*) AS `count`
        FROM `incomming_call`
        WHERE DATE(date) >= '$start_time'
        AND DATE(date) <= '$end_time'
        AND source_id = 1
        AND phone!=''
        AND actived=1"));

    $data		= array('page' => array(
        'answer_call' => '',
        'technik_info' => '',
        'report_info' => '',
        'answer_call_info' => '',
        'answer_call_by_queue' => '',
        'disconnection_cause' => '',
        'unanswer_call' => '',
        'disconnection_cause_unanswer' => '',
        'unanswered_calls_by_queue' => '',
        'totals' => '',
        'call_distribution_per_day' => '',
        'call_distribution_per_hour' => '',
        'call_distribution_per_day_of_week' => '',
        'service_level' => ''
    ));
    

    
 /// ------------------------------შინაარსობრივი ინფორმაცია
 
    /// შემოსული ზარები ტიპების მიხედვით
    $result = mysql_query("SELECT
                                info_category.`name` AS type,
                                COUNT(incomming_call.id),
                                CONCAT(ROUND(COUNT(incomming_call.id)/(SELECT	COUNT(incomming_call.id)
                                FROM incomming_call
                                JOIN info_category ON incomming_call.information_sub_category_id=info_category.id and info_category.actived=1
                                AND info_category.parent_id=0
                                WHERE DATE(`incomming_call`.`date`) >= '$start_time' AND DATE(`incomming_call`.`date`) <= '$end_time'
                            )*100,2),'%')	 AS `PERCENT`
                                FROM incomming_call
                                JOIN info_category ON incomming_call.information_sub_category_id=info_category.id and info_category.actived=1
                                AND info_category.parent_id=0
                                WHERE 	DATE(`incomming_call`.`date`) >= '$start_time' AND DATE(`incomming_call`.`date`) <= '$end_time'
                                GROUP 	BY  type");
    
    $chart = new PieChart();    
    $dataSet = new XYDataSet();
    $chart->setDataSet($dataSet);
    
    while($row = mysql_fetch_array($result)){
    
        $dataSet->addPoint(new Point($row[0], $row[1]));
    
        $data['page']['by_type'] .= '
    
	    <tr>
					<td>'.$row[0].'</td>
					<td>'.$row[1].'</td>
					<td>'.$row[2].'</td>
       </tr> ';
    
    }
    
    $chart->setTitle("შემოსული ზარები ტიპების მიხედვით");
    $chart->render("generated/by_type.png");
    

    /// შემოსული  ინფორმაცია  ქვე-კატეგორიების  მიხედვით
    
		$result = mysql_query("	SELECT 	info_category.`name` AS d_name,
										COUNT(*),
										CONCAT(ROUND(COUNT(*)/(
													SELECT COUNT(*)
																		FROM 	incomming_call
																		JOIN  info_category AS sub ON sub.`name`='ინფორმაცია'
																		JOIN 	info_category ON incomming_call.information_category_id=info_category.id AND info_category.parent_id=sub.id
																		and info_category.actived=1
																		WHERE DATE(`incomming_call`.`date`) >= '$start' AND DATE(`incomming_call`.`date`) <= '$end' )*100,2),'%')
										FROM 	incomming_call
										JOIN  	info_category AS sub ON sub.`name`='ინფორმაცია'
										JOIN 	info_category ON incomming_call.information_category_id=info_category.id AND info_category.parent_id=sub.id
										and info_category.actived=1
										WHERE DATE(`incomming_call`.`date`) >= '$start' AND DATE(`incomming_call`.`date`) <= '$end'
										GROUP BY 	d_name");
    
    $chart = new PieChart();    
    $dataSet = new XYDataSet();
    $chart->setDataSet($dataSet);
    
    while($row = mysql_fetch_array($result)){
    
        $dataSet->addPoint(new Point($row[0], $row[1]));
    
        $data['page']['by_category'] .= '
    
	    <tr>
					<td>'.$row[0].'</td>
					<td>'.$row[1].'</td>
					<td>'.$row[2].'</td>
       </tr> ';
    
    }
    
    $chart->setTitle("შემოსული  ინფორმაცია  ქვე-კატეგორიების  მიხედვით");
    $chart->render("generated/by_category.png");
    
  //---  შემოსული  პრეტენზია  ქვე-კატეგორიების  მიხედვით.
    
    $result = mysql_query("	SELECT 	info_category.`name` AS d_name,
										COUNT(*),
										CONCAT(ROUND(COUNT(*)/(
													SELECT COUNT(*)
																		FROM 	incomming_call
																		JOIN  info_category AS sub ON sub.`name`='პრეტენზია'
																		JOIN 	info_category ON incomming_call.information_category_id=info_category.id AND info_category.parent_id=sub.id
																		and info_category.actived=1
																		WHERE DATE(`incomming_call`.`date`) >= '$start' AND DATE(`incomming_call`.`date`) <= '$end' )*100,2),'%')
										FROM 	incomming_call
										JOIN  	info_category AS sub ON sub.`name`='პრეტენზია'
										JOIN 	info_category ON incomming_call.information_category_id=info_category.id AND info_category.parent_id=sub.id
										and info_category.actived=1
										WHERE DATE(`incomming_call`.`date`) >= '$start' AND DATE(`incomming_call`.`date`) <= '$end'
										GROUP BY 	d_name");
    
    $chart = new PieChart();    
    $dataSet = new XYDataSet();
    $chart->setDataSet($dataSet);
    
    while($row = mysql_fetch_array($result)){
    
        $dataSet->addPoint(new Point($row[0], $row[1]));
    
        $data['page']['pr_by_category'] .= '
    
	    <tr>
					<td>'.$row[0].'</td>
					<td>'.$row[1].'</td>
					<td>'.$row[2].'</td>
       </tr> ';
    
    }
    
    $chart->setTitle("შემოსული  პრეტენზია  ქვე-კატეგორიების  მიხედვით");
    $chart->render("generated/pr_by_category.png");
 ////////ინტერესი პროდუქტის  კატეგორიის  მიხედვით
		$result = mysql_query("SELECT 	incomming_call.`production_category_id` AS c_name,
										COUNT(*),
										CONCAT(ROUND(COUNT(*)/(
											SELECT COUNT(*) FROM incomming_call
											WHERE incomming_call.production_type=2 and DATE(`incomming_call`.`date`) >= '$start' AND DATE(`incomming_call`.`date`) <= '$end' AND production_category_id!='' AND production_category_id!='0'
												)*100,2),'%')
							FROM 		incomming_call

							WHERE incomming_call.production_type=2 and DATE(`incomming_call`.`date`) >= '$start' AND DATE(`incomming_call`.`date`) <= '$end' AND production_category_id!='' AND production_category_id!='0'
							GROUP BY c_name");
    $chart = new PieChart();
    $dataSet = new XYDataSet();
    $chart->setDataSet($dataSet);
    
    while($row = mysql_fetch_array($result)){
    
        $dataSet->addPoint(new Point($row[0], $row[1]));
    
        $data['page']['i_by_p_category'] .= '
    
	    <tr>
					<td>'.$row[0].'</td>
					<td>'.$row[1].'</td>
					<td>'.$row[2].'</td>
       </tr> ';
    
    }
    
    $chart->setTitle("ინტერესი პროდუქტის  კატეგორიის  მიხედვით");
    $chart->render("generated/i_by_p_category.png");
    
    //..ინტერესი ბრენდების  მიხედვით
		$result = mysql_query("SELECT 	incomming_call.`production_id` AS c_name,
										COUNT(*),
										CONCAT(ROUND(COUNT(*)/(
											SELECT COUNT(*) FROM incomming_call
											WHERE incomming_call.production_type=2 and DATE(`incomming_call`.`date`) >= '$start' AND DATE(`incomming_call`.`date`) <= '$end' AND incomming_call.production_id!='' AND incomming_call.production_id!='0'
												)*100,2),'%')
							FROM 		incomming_call

							WHERE incomming_call.production_type=2 and DATE(`incomming_call`.`date`) >= '$start' AND DATE(`incomming_call`.`date`) <= '$end' AND incomming_call.production_id!='' AND incomming_call.production_id!='0'
							GROUP BY c_name");
    $chart = new PieChart();    
    $dataSet = new XYDataSet();
    $chart->setDataSet($dataSet);
    
    while($row = mysql_fetch_array($result)){
    
        $dataSet->addPoint(new Point($row[0], $row[1]));
    
        $data['page']['i_by_brend'] .= '
    
	    <tr>
					<td>'.$row[0].'</td>
					<td>'.$row[1].'</td>
					<td>'.$row[2].'</td>
       </tr> ';
    
    }
    
    $chart->setTitle("ინტერესი ბრენდების  მიხედვით");
    $chart->render("generated/i_by_brend.png");
    
    ////////პრეტენზია პროდუქტის  კატეგორიის  მიხედვით
		$result = mysql_query("SELECT 	incomming_call.`production_category_id` AS c_name,
										COUNT(*),
										CONCAT(ROUND(COUNT(*)/(
											SELECT COUNT(*) FROM incomming_call
											WHERE incomming_call.information_sub_category_id=37 and DATE(`incomming_call`.`date`) >= '$start' AND DATE(`incomming_call`.`date`) <= '$end' AND production_category_id!='' AND production_category_id!='0'
												)*100,2),'%')
							FROM 		incomming_call

							WHERE incomming_call.information_sub_category_id=37 and DATE(`incomming_call`.`date`) >= '$start' AND DATE(`incomming_call`.`date`) <= '$end' AND production_category_id!='' AND production_category_id!='0'
							GROUP BY c_name");
    $chart = new PieChart();
    $dataSet = new XYDataSet();
    $chart->setDataSet($dataSet);
    
    while($row = mysql_fetch_array($result)){
    
        $dataSet->addPoint(new Point($row[0], $row[1]));
    
        $data['page']['p_by_category'] .= '
    
	    <tr>
					<td>'.$row[0].'</td>
					<td>'.$row[1].'</td>
					<td>'.$row[2].'</td>
       </tr> ';
    
    }
    
    $chart->setTitle("პრეტენზია პროდუქტის  კატეგორიის  მიხედვით");
    $chart->render("generated/p_by_category.png");
  
    
 //////////////// პრეტენზია ბრენდის მიხედვით
		$result = mysql_query("SELECT 	incomming_call.`production_id` AS c_name,
										COUNT(*),
										CONCAT(ROUND(COUNT(*)/(
											SELECT COUNT(*) FROM incomming_call
											WHERE incomming_call.information_sub_category_id=37 and DATE(`incomming_call`.`date`) >= '$start' AND DATE(`incomming_call`.`date`) <= '$end' AND incomming_call.production_id!='0'	AND incomming_call.production_id!=''
												)*100,2),'%')
							FROM 		incomming_call

							WHERE incomming_call.information_sub_category_id=37 and DATE(`incomming_call`.`date`) >= '$start' AND DATE(`incomming_call`.`date`) <= '$end' AND incomming_call.production_id!='0'
							AND incomming_call.production_id!=''
							GROUP BY c_name");
    $chart = new PieChart();
    $dataSet = new XYDataSet();
    $chart->setDataSet($dataSet);
    
    while($row = mysql_fetch_array($result)){
    
        $dataSet->addPoint(new Point($row[0], $row[1]));
    
        $data['page']['p_by_brend'] .= '
    
	    <tr>
					<td>'.$row[0].'</td>
					<td>'.$row[1].'</td>
					<td>'.$row[2].'</td>
       </tr> ';
    
    }
    
    $chart->setTitle("პრეტენზია ბრენდის მიხედვით");
    $chart->render("generated/p_by_brend.png");   
    
    
//------------------------------- ტექნიკური ინფორმაცია

    $row_answer = mysql_fetch_assoc(mysql_query("  SELECT	COUNT(*) AS `count`,
													        q.queue AS `queue`
											        FROM	queue_stats AS qs,
											        qname AS q,
											        qagent AS ag,
											        qevent AS ac
											        WHERE qs.qname = q.qname_id
												        AND qs.qagent = ag.agent_id
												        AND qs.qevent = ac.event_id
												        AND DATE(qs.datetime) >= '$start_time' AND DATE(qs.datetime) <= '$end_time'
												        AND q.queue IN ($queue)
												        AND ag.agent in ($agent)
												        AND ac.event IN ( 'COMPLETECALLER', 'COMPLETEAGENT')
												        ORDER BY ag.agent"));

    $row_abadon = mysql_fetch_assoc(mysql_query("	SELECT 	COUNT(*) AS `count`,
											        		ROUND((SUM(qs.info3) / COUNT(*))) AS `sec`
											        FROM	queue_stats AS qs,
											        qname AS q,
											        qagent AS ag,
											        qevent AS ac
											        WHERE qs.qname = q.qname_id
											        AND qs.qagent = ag.agent_id
											        AND qs.qevent = ac.event_id
											        AND DATE(qs.datetime) >= '$start_time'
											        AND DATE(qs.datetime) <= '$end_time'
											        AND q.queue IN ($queue)
											        AND ac.event IN ('ABANDON', 'EXITWITHTIMEOUT')"));
    $chart = new PieChart(400, 250);
    $dataSet = new XYDataSet();
    $dataSet->addPoint(new Point('ნაპასუხები', $row_answer[count]));
    $dataSet->addPoint(new Point('უპასუხო', $row_abadon[count]));
    $chart->setDataSet($dataSet);
    $chart->setTitle("ტექნიკური ინფორმაცია");
    $chart->render("generated/technical_info1.png");

    $chart = new PieChart(400,250);
    $dataSet = new XYDataSet();
    $dataSet->addPoint(new Point('დამუშავებული', $row_done_blank[count]));
    $dataSet->addPoint(new Point('დაუმუშავებელი', ($row_answer[count]-$row_done_blank[count])));
    $chart->setDataSet($dataSet);
    $chart->setTitle("ტექნიკური ინფორმაცია");
    $chart->render("generated/technical_info2.png");



    $data['page']['technik_info'] = '

                    <td>ზარი</td>
                    <td>'.($row_answer[count] + $row_abadon[count]).'</td>
                    <td>'.$row_answer[count].'</td>
                    <td>'.$row_abadon[count].'</td>
                    <td>'.$row_done_blank[count].'</td>
                    <td>'.round(((($row_answer[count]) / ($row_answer[count] + $row_abadon[count])) * 100),2).' %</td>
                    <td>'.round(((($row_abadon[count]) / ($row_answer[count] + $row_abadon[count])) * 100),2).' %</td>
                    <td>'.round(((($row_done_blank[count]) / ($row_answer[count])) * 100),2).' %</td>

							';
    // -----------------------------------------------------

    //------------------------------- ნაპასუხები ზარები რიგის მიხედვით

    $data['page']['answer_call'] = '
							<tr><td>'.$row_answer[queue].'</td><td>'.$row_answer[count].' ზარი</td><td>'.round(((($row_answer[count]) / ($row_answer[count])) * 100)).' %</td></tr>
							';
    $chart = new VerticalBarChart();

    $dataSet = new XYDataSet();
    $dataSet->addPoint(new Point($row_answer[queue], $row_answer[count]));
    $chart->setDataSet($dataSet);

    $chart->setTitle("ნაპასუხები ზარები რიგის მიხედვით");
    $chart->render("generated/answer_call.png");

    //-------------------------------------------------------

    //------------------------------- მომსახურების დონე(Service Level)



    $res_service_level = mysql_query("	SELECT 	qs.info1
								        FROM 	queue_stats AS qs,
									        qname AS q,
									        qagent AS ag,
									        qevent AS ac
									    WHERE 	qs.qname = q.qname_id
									        AND qs.qagent = ag.agent_id
									        AND qs.qevent = ac.event_id
									        AND DATE(qs.datetime) >= '$start_time'
									        AND DATE(qs.datetime) <= '$end_time'
									        AND q.queue IN ($queue)
									        AND ag.agent in ($agent)
									        AND ac.event IN ('CONNECT')
        ");
    $w15 = 0;
    $w30 = 0;
    $w45 = 0;
    $w60 = 0;
    $w75 = 0;
    $w90 = 0;
    $w91 = 0;




    while ($res_service_level_r = mysql_fetch_assoc($res_service_level)) {

    if ($res_service_level_r['info1'] < 15) {
    $w15++;
    }

    if ($res_service_level_r['info1'] < 30){
    $w30++;
    }

    if ($res_service_level_r['info1'] < 45){
    $w45++;
    }

		if ($res_service_level_r['info1'] < 60){
		$w60++;
    }

		if ($res_service_level_r['info1'] < 75){
		$w75++;
    }

		if ($res_service_level_r['info1'] < 90){
		$w90++;
}

$w91++;

}
$d15 = $w15;
$d30 = $w30 - $w15;
$d45 = $w45 - $w30;
$d60 = $w60 - $w45;
$d75 = $w75 - $w60;
$d90 = $w90 - $w75;
$d91 = $w91 - $w90;


$p15 = round($w15 * 100 / $w91);
$p30 = round($w30 * 100 / $w91);
$p45 = round($w45 * 100 / $w91);
$p60 = round($w60 * 100 / $w91);
$p75 = round($w75 * 100 / $w91);
$p90 = round($w90 * 100 / $w91);

$chart = new VerticalBarChart();

$dataSet = new XYDataSet();
$dataSet->addPoint(new Point("15 წამში", $d15));
$dataSet->addPoint(new Point("30 წამში", $d30));
$dataSet->addPoint(new Point("45 წამში", $d45));
$dataSet->addPoint(new Point("60 წამში", $d60));
$dataSet->addPoint(new Point("75 წამში5",$d75));
$dataSet->addPoint(new Point("90 წამში", $d90));
$dataSet->addPoint(new Point("90+ წამში",$d91));
$chart->setDataSet($dataSet);

$chart->setTitle("ნაპასუხები ზარები წამების მიხედვით");
$chart->render("generated/service_level.png");



$data['page']['service_level'] = '

							<tr class="odd">
						 		<td>15 წამში</td>
					 			<td>'.$w15.'</td>
					 			<td>'.$d15.'</td>
					 			<td>'.$p15.'%</td>
					 		</tr>
				 			<tr>
						 		<td>30 წამში</td>
					 			<td>'.$w30.'</td>
					 			<td>'.$d30.'</td>
					 			<td>'.$p30.'%</td>
					 		</tr>
				 			<tr class="odd">
						 		<td>45 წამში</td>
					 			<td>'.$w45.'</td>
					 			<td>'.$d45.'</td>
					 			<td>'.$p45.'%</td>
					 		</tr>
				 			<tr>
						 		<td>60 წამში</td>
					 			<td>'.$w60.'</td>
					 			<td>'.$d60.'</td>
					 			<td>'.$p60.'%</td>
					 		</tr>
				 			<tr class="odd">
						 		<td>75 წამში</td>
					 			<td>'.$w75.'</td>
					 			<td>'.$d75.'</td>
					 			<td>'.$p75.'%</td>
					 		</tr>
					 		<tr>
						 		<td>90 წამში</td>
					 			<td>'.$w90.'</td>
					 			<td>'.$d90.'</td>
					 			<td>'.$p90.'%</td>
					 		</tr>
					 		<tr class="odd">
						 		<td>90+ წამში</td>
					 			<td>'.$w91.'</td>
					 			<td>'.$d91.'</td>
					 			<td>100%</td>
					 		</tr>
							';

//-------------------------------------------------------

//---------------------------------------- რეპორტ ინფო

$data['page']['report_info'] = '

                <tr>
                    <td class="tdstyle">რიგი:</td>
                    <td>'.$queue.'</td>
                    </tr>
                <tr>
                    <td class="tdstyle">საწყისი თარიღი:</td>
                    <td>'.$start_time.'</td>
                </tr>
                <tr>
                    <td class="tdstyle">დასრულების თარიღი:</td>
                    <td>'.$end_time.'</td>
                </tr>
                <tr>
                    <td class="tdstyle">პერიოდი:</td>
                    <td>'.$day_format.' დღე</td>
                </tr>

							';

		//----------------------------------------------


		//------------------------------------ ნაპასუხები ზარები

		$row_transfer = mysql_fetch_assoc(mysql_query("	SELECT	COUNT(*) AS `count`
														FROM	queue_stats AS qs,
															qname AS q,
															qagent AS ag,
															qevent AS ac
														WHERE qs.qname = q.qname_id
															AND qs.qagent = ag.agent_id
															AND qs.qevent = ac.event_id
															AND DATE(qs.datetime) >= '$start_time' AND DATE(qs.datetime) <= '$end_time'
															AND q.queue IN ($queue)
															AND ag.agent in ($agent)
															AND ac.event IN ( 'TRANSFER')
															ORDER BY ag.agent"));

		$row_clock = mysql_fetch_assoc(mysql_query("	SELECT	ROUND((SUM(qs.info1) / COUNT(*)),2) AS `hold`,
															    ROUND((SUM(qs.info2) / COUNT(*)),2) AS `sec`,
															    ROUND((SUM(qs.info2) / 60 ),2) AS `min`
													    FROM 	queue_stats AS qs,
														    qname AS q,
														    qagent AS ag,
														    qevent AS ac
													    WHERE	qs.qname = q.qname_id
														    AND qs.qagent = ag.agent_id
														    AND qs.qevent = ac.event_id
														    AND q.queue IN ($queue)
														    AND DATE(qs.datetime) >= '$start_time' AND DATE(qs.datetime) <= '$end_time'
														    AND ac.event IN ('COMPLETECALLER', 'COMPLETEAGENT')
														    ORDER BY qs.datetime"));




		    $data['page']['answer_call_info'] = '

		    <tr>
		    <td class="tdstyle">ნაპასუხები ზარები</td>
<td>'.$row_answer[count].' ზარი</td>
</tr>
<tr>
		        <td class="tdstyle">გადამისამართებული ზარები</td>
<td>'.$row_transfer[count].' ზარი</td>
</tr>
		            <tr>
<td class="tdstyle">საშ. ხანგძლივობა:</td>
<td>'.$row_clock[sec].' წამი</td>
		                </tr>
<tr>
<td class="tdstyle">სულ საუბრის ხანგძლივობა:</td>
<td>'.$row_clock[min].' წუთი</td>
</tr>
<tr>
<td class="tdstyle">ლოდინის საშ. ხანგძლივობა:</td>
<td>'.$row_clock[hold].' წამი</td>
</tr>

		';

//---------------------------------------------


 //--------------------------- ნაპასუხები ზარები ოპერატორების მიხედვით

	    $ress =mysql_query("SELECT 	ag.agent as `agent`,
							    count(ev.event) AS `num`,
							    round(((count(ev.event) / (

							    SELECT count(ev.event) AS num
							    FROM queue_stats AS qs, qname AS q, qevent AS ev
							    WHERE qs.qname = q.qname_id
							    and qs.qevent = ev.event_id
							    and DATE(qs.datetime) >= '$start_time'
							    and DATE(qs.datetime) <= '$end_time'
							    and q.queue IN ($queue)
							    AND ag.agent in ($agent)
							    AND ev.event IN ('COMPLETECALLER', 'COMPLETEAGENT')

							    )) * 100),2) AS `call_pr`,
							    ROUND((sum(qs.info2) / 60),2) AS `call_time`,

							    round(((sum(qs.info2) / (

							    SELECT sum(qs.info2)
							    FROM queue_stats AS qs, qname AS q, qevent AS ev
							    WHERE qs.qname = q.qname_id
							    and qs.qevent = ev.event_id
							    and DATE(qs.datetime) >= '$start_time'
							    and DATE(qs.datetime) <= '$end_time'
							    and q.queue IN ($queue)
							    AND ag.agent in ($agent)
							    AND ev.event IN ('COMPLETECALLER', 'COMPLETEAGENT')

							    ))* 100),2) AS `call_time_pr`,
							    TIME_FORMAT(SEC_TO_TIME(sum(qs.info2) / count(ev.event)), '%i:%s') AS `avg_call_time`,
							    sum(qs.info1) AS `hold_time`,
							    ROUND((sum(qs.info1) / count(ev.event)),2) AS `avg_hold_time`
							    FROM queue_stats AS qs, qname AS q, qevent AS ev, qagent AS `ag` WHERE ag.agent_id = qs.qagent AND
							    qs.qname = q.qname_id and qs.qevent = ev.event_id
							    AND DATE(qs.datetime) >= '$start_time'
 	AND DATE(qs.datetime) <= '$end_time'
 	AND q.queue IN ($queue)
 	AND ag.agent in ($agent)
 	AND ev.event IN ('COMPLETECALLER', 'COMPLETEAGENT')
 	GROUP BY ag.agent");

	$chart = new VerticalBarChart();

	$dataSet = new XYDataSet();
	$chart->setDataSet($dataSet);

while($row = mysql_fetch_assoc($ress)){

    $dataSet->addPoint(new Point($row[agent], $row[num]));

	$data['page']['answer_call_by_queue'] .= '

	    <tr>
					<td>'.$row[agent].'</td>
					<td>'.$row[num].'</td>
					    <td>'.$row[call_pr].' %</td>
					    <td>'.$row[call_time].' წუთი</td>
					    <td>'.$row[call_time_pr].' %</td>
					    <td>'.$row[avg_call_time].' წუთი</td>
					    <td>'.$row[hold_time].' წამი</td>
					    <td>'.$row[avg_hold_time].' წამი</td>
					    </tr>

					    ';

}

$chart->setTitle("ნაპასუხები ზარები ოპერატორების მიხედვით");
$chart->render("generated/answer_call_by_queue.png");


//----------------------------------------------------

//--------------------------- კავშირის გაწყვეტის მიზეზი


$row_COMPLETECALLER = mysql_fetch_assoc(mysql_query("	SELECT	COUNT(*) AS `count`,
																q.queue AS `queue`
														FROM	queue_stats AS qs,
															qname AS q,
															qagent AS ag,
															qevent AS ac
														WHERE qs.qname = q.qname_id
															AND qs.qagent = ag.agent_id
															AND qs.qevent = ac.event_id
															AND DATE(qs.datetime) >= '$start_time' AND DATE(qs.datetime) <= '$end_time'
															AND q.queue IN ($queue)
															AND ag.agent in ($agent)
															AND ac.event IN ( 'COMPLETECALLER')
															ORDER BY ag.agent"));

$row_COMPLETEAGENT = mysql_fetch_assoc(mysql_query("	SELECT	COUNT(*) AS `count`,
																q.queue AS `queue`
														FROM	queue_stats AS qs,
															qname AS q,
															qagent AS ag,
															qevent AS ac
														WHERE qs.qname = q.qname_id
															AND qs.qagent = ag.agent_id
															AND qs.qevent = ac.event_id
															AND DATE(qs.datetime) >= '$start_time' AND DATE(qs.datetime) <= '$end_time'
															AND q.queue IN ($queue)
															AND ag.agent in ($agent)
															AND ac.event IN (  'COMPLETEAGENT')
															ORDER BY ag.agent"));
$percent=100;
$percent1=round((($row_COMPLETEAGENT[count] / $row_COMPLETECALLER[count]) * 100),2);
$perc = $percent - $percent1;
$data['page']['disconnection_cause'] = '

<tr>
<td class="tdstyle">ოპერატორმა გათიშა:</td>
    <td>'.$row_COMPLETEAGENT[count].' ზარი</td>
					<td>'.round((($row_COMPLETEAGENT[count] / $row_COMPLETECALLER[count]) * 100),2).' %</td>
					</tr>
					<tr>
					<td class="tdstyle">აბონენტმა გათიშა:</td>
        <td>'.$row_COMPLETECALLER[count].' ზარი</td>
					<td>'.$perc.' %</td>
					</tr>

							';

$chart = new VerticalBarChart();

$dataSet = new XYDataSet();
$dataSet->addPoint(new Point("ოპერატორმა გათიშა", $row_COMPLETEAGENT[count]));
$dataSet->addPoint(new Point("აბონენტმა გათიშა", $row_COMPLETECALLER[count]));
$chart->setDataSet($dataSet);

$chart->setTitle("კავშირის გაწყვეტის მიზეზი");
$chart->render("generated/disconnection_cause.png");

//-----------------------------------------------

//----------------------------------- უპასუხო ზარები


$data['page']['unanswer_call'] = '

<tr>
<td class="tdstyle">უპასუხო ზარების რაოდენობა:</td>
<td>'.$row_abadon[count].' ზარი</td>
    </tr>
					<tr>
					<td class="tdstyle">ლოდინის საშ. დრო კავშირის გაწყვეტამდე:</td>
					<td>'.$row_abadon[sec].' წამი</td>
					</tr>
					<tr>
					<td class="tdstyle">საშ. რიგში პოზიცია კავშირის გაწყვეტამდე:</td>
					<td>1</td>
					</tr>
					<tr>
					<td class="tdstyle">საშ. საწყისი პოზიცია რიგში:</td>
					<td>1</td>
					</tr>

							';


//--------------------------------------------


//----------------------------------- კავშირის გაწყვეტის მიზეზი

	$row_timeout = mysql_fetch_assoc(mysql_query("	SELECT 	COUNT(*) AS `count`
													FROM 	queue_stats AS qs,
														qname AS q,
														qagent AS ag,
														qevent AS ac
													WHERE qs.qname = q.qname_id
														AND qs.qagent = ag.agent_id
														AND qs.qevent = ac.event_id
														AND DATE(qs.datetime) >= '$start_time' AND DATE(qs.datetime) <= '$end_time'
														AND q.queue IN ($queue)
														AND ac.event IN ('EXITWITHTIMEOUT')
														ORDER BY qs.datetime"));


					$data['page']['disconnection_cause_unanswer'] = '

					<tr>
					<td class="tdstyle">აბონენტმა გათიშა</td>
			      <td>'.$row_abadon[count].' ზარი</td>
			      <td>'.round((($row_abadon[count] / $row_abadon[count]) * 100),2).' %</td>
			          </tr>
			          <tr>
			          <td class="tdstyle">დრო ამოიწურა</td>
			          <td>'.$row_timeout[count].' ზარი</td>
			      <td>'.round((($row_timeout[count] / $row_timeout[count]) * 100),2).' %</td>
			          </tr>

							';
					
					$chart = new VerticalBarChart();
					
					$dataSet = new XYDataSet();
					$dataSet->addPoint(new Point("ოპერატორმა გათიშა", $row_abadon[count]));
					$dataSet->addPoint(new Point("დრო ამოიწურა", $row_timeout[count]));
					$chart->setDataSet($dataSet);
					
					$chart->setTitle("კავშირის გაწყვეტის მიზეზი (უპასუხო)");
					$chart->render("generated/disconnection_cause_unanswer.png");

//--------------------------------------------

			          //------------------------------ უპასუხო ზარები რიგის მიხედვით

					$Unanswered_Calls_by_Queue = mysql_fetch_assoc(mysql_query("	SELECT 	COUNT(*) AS `count`,
																							q.queue as `queue`
																					FROM 	queue_stats AS qs,
																						qname AS q,
																						qagent AS ag,
																						qevent AS ac
																					WHERE qs.qname = q.qname_id
																						AND qs.qagent = ag.agent_id
																						AND qs.qevent = ac.event_id
																						AND DATE(qs.datetime) >= '$start_time' AND DATE(qs.datetime) <= '$end_time'
																						AND q.queue IN ($queue)
																						AND ac.event IN ('ABANDON')
																						ORDER BY qs.datetime"));

					$data['page']['unanswered_calls_by_queue'] = '

					<tr><td>'.$Unanswered_Calls_by_Queue[queue].'</td><td>'.$Unanswered_Calls_by_Queue[count].' ზარი</td><td>'.round((($Unanswered_Calls_by_Queue[count] / $Unanswered_Calls_by_Queue[count]) * 100),2).' %</td></tr>

					    ';
					$chart = new VerticalBarChart();

					$dataSet = new XYDataSet();
					$dataSet->addPoint(new Point($Unanswered_Calls_by_Queue[queue], $Unanswered_Calls_by_Queue[count]));
					$chart->setDataSet($dataSet);

					$chart->setTitle("უპასუხო ზარები რიგის მიხედვით");
					$chart->render("generated/unanswered_calls_by_queue.png");

					    //---------------------------------------------------

//------------------------------------------- სულ

					$data['page']['totals'] = '

					<tr>
					<td class="tdstyle">ნაპასუხები ზარების რაოდენობა:</td>
		          <td>'.$row_answer[count].' ზარი</td>
	            </tr>
                <tr>
                  <td class="tdstyle">უპასუხო ზარების რაოდენობა:</td>
                  <td>'.$row_abadon[count].' ზარი</td>
                </tr>
		        <tr>
                  <td class="tdstyle">ოპერატორი შევიდა:</td>
		          <td>0</td>
	            </tr>
                <tr>
                  <td class="tdstyle">ოპერატორი გავიდა:</td>
                  <td>0</td>
                </tr>

							';

//------------------------------------------------


//-------------------------------- ზარის განაწილება დღეების მიხედვით

					$res = mysql_query("	SELECT 	DATE(qs.datetime) AS `datetime`,
													COUNT(*) AS `answer_count`,
													ROUND((( COUNT(*) / (
													SELECT 	COUNT(*) AS `count`
														FROM 	queue_stats AS qs,
															qname AS q,
															qagent AS ag,
															qevent AS ac
													WHERE qs.qname = q.qname_id
														AND qs.qagent = ag.agent_id
														AND qs.qevent = ac.event_id
														AND DATE(qs.datetime) >= '$start_time'
														AND DATE(qs.datetime) <= '$end_time'
														AND q.queue IN ($queue,'NONE')
														AND ac.event IN ('COMPLETECALLER','COMPLETEAGENT')
													)) *100),2) AS `call_answer_pr`,
													TIME_FORMAT(SEC_TO_TIME((SUM(qs.info2) / COUNT(*))), '%i:%s') AS `avg_durat`,
													ROUND((SUM(qs.info1) / COUNT(*))) AS `avg_hold`
											FROM 	queue_stats AS qs,
												qname AS q,
												qagent AS ag,
												qevent AS ac
											WHERE qs.qname = q.qname_id
												AND qs.qagent = ag.agent_id
												AND qs.qevent = ac.event_id
												AND DATE(qs.datetime) >= '$start_time'
												AND DATE(qs.datetime) <= '$end_time'
												AND q.queue IN ($queue,'NONE')
												AND ac.event IN ('COMPLETECALLER','COMPLETEAGENT')
												GROUP BY DATE(qs.datetime)
					");

					$ress = mysql_query("
											SELECT 	COUNT(*) AS `unanswer_call`,
						
													ROUND((( COUNT(*) / (
															SELECT 	COUNT(*) AS `count`
															FROM 		queue_stats AS qs,
																qname AS q,
																qagent AS ag,
																qevent AS ac
															WHERE qs.qname = q.qname_id
																AND qs.qagent = ag.agent_id
																AND qs.qevent = ac.event_id
																AND DATE(qs.datetime) >= '$start_time'
																AND DATE(qs.datetime) <= '$end_time'
																AND q.queue IN ($queue,'NONE')
																AND ac.event IN ('ABANDON','EXITWITHTIMEOUT')
															)) *100),2) AS `call_unanswer_pr`
											FROM 	queue_stats AS qs,
												qname AS q,
												qagent AS ag,
												qevent AS ac
											WHERE qs.qname = q.qname_id
												AND qs.qagent = ag.agent_id
												AND qs.qevent = ac.event_id
												AND DATE(qs.datetime) >= '$start_time'
												AND DATE(qs.datetime) <= '$end_time'
												AND q.queue IN ($queue,'NONE')
												AND ac.event IN ('ABANDON', 'EXITWITHTIMEOUT')
												GROUP BY DATE(qs.datetime)
											");


					$chart = new VerticalBarChart();
					$chart1 = new VerticalBarChart();

					$dataSet = new XYDataSet();
					$dataSet1 = new XYDataSet();

					while($row = mysql_fetch_assoc($res)){
					$roww = mysql_fetch_assoc($ress);
					$data['page']['call_distribution_per_day'] .= '
					<tr class="odd">
					<td>'.$row[datetime].'</td>
					<td>'.$row[answer_count].'</td>
					<td>'.$row[call_answer_pr].' %</td>
					<td>'.(($roww[unanswer_call]!='')?$roww[unanswer_call]:"0").'</td>
					<td>'.(($roww[call_unanswer_pr]!='')?$roww[call_unanswer_pr]:"0").' %</td>
					<td>'.$row[avg_durat].' წუთი</td>
					<td>'.$row[avg_hold].' წამი</td>
					<td></td>
					<td></td>
					</tr>

					';
					$dataSet->addPoint(new Point($row[datetime], $row[answer_count]));
					$dataSet1->addPoint(new Point($row[datetime], (($roww[unanswer_call]!='')?$roww[unanswer_call]:"0")));

	}
	$chart->setDataSet($dataSet);
	$chart1->setDataSet($dataSet1);
	$chart->setTitle("ნაპასუხები ზარები დღეების მიხედვით");
	$chart1->setTitle("უპასუხო ზარები დღეების მიხედვით");
	$chart->render("generated/answer_call_per_day.png");
	$chart1->render("generated/unanswer_call_per_day.png");


//----------------------------------------------------


//-------------------------------- ზარის განაწილება საათების მიხედვით






$res124 = mysql_query("
SELECT  HOUR(qs.datetime) AS `datetime`,
    COUNT(*) AS `answer_count`,
					ROUND((( COUNT(*) / (
					SELECT 	COUNT(*) AS `count`
					FROM 	queue_stats AS qs,
					qname AS q,
					qagent AS ag,
					qevent AS ac
					WHERE qs.qname = q.qname_id
					AND qs.qagent = ag.agent_id
					AND qs.qevent = ac.event_id
					AND DATE(qs.datetime) >= '$start_time'
					AND DATE(qs.datetime) <= '$end_time'
					AND q.queue IN ($queue,'NONE')
					AND ac.event IN ('COMPLETECALLER','COMPLETEAGENT')
					)) *100),2) AS `call_answer_pr`,
					ROUND((SUM(qs.info2) / COUNT(*)),0) AS `avg_durat`,
					ROUND((SUM(qs.info1) / COUNT(*)),0) AS `avg_hold`
					FROM 	queue_stats AS qs,
					qname AS q,
					qagent AS ag,
					qevent AS ac
					WHERE qs.qname = q.qname_id
					AND qs.qagent = ag.agent_id
					AND qs.qevent = ac.event_id
					AND DATE(qs.datetime) >= '$start_time'
					AND DATE(qs.datetime) <= '$end_time'
					AND q.queue IN ($queue,'NONE')
					AND ac.event IN ('COMPLETECALLER','COMPLETEAGENT')
					GROUP BY HOUR(qs.datetime)
					");

					$res1244 = mysql_query("
					SELECT  HOUR(qs.datetime) AS `datetime`,
					COUNT(*) AS `unanswer_count`,
					ROUND((( COUNT(*) / (
					SELECT 	COUNT(*) AS `count`
					FROM 	queue_stats AS qs,
					qname AS q,
					qagent AS ag,
					qevent AS ac
					WHERE qs.qname = q.qname_id
					AND qs.qagent = ag.agent_id
					AND qs.qevent = ac.event_id
					AND DATE(qs.datetime) >= '$start_time'
					AND DATE(qs.datetime) <= '$end_time'
					AND q.queue IN ($queue,'NONE')
					AND ac.event IN ('ABANDON','EXITWITHTIMEOUT')
					)) *100),2) AS `call_unanswer_pr`
					FROM 	queue_stats AS qs,
					qname AS q,
					qagent AS ag,
					qevent AS ac
					WHERE qs.qname = q.qname_id
					AND qs.qagent = ag.agent_id
					AND qs.qevent = ac.event_id
					AND DATE(qs.datetime) >= '$start_time'
					    AND DATE(qs.datetime) <= '$end_time'
					    AND q.queue IN ($queue,'NONE')
					    AND ac.event IN ('ABANDON','EXITWITHTIMEOUT')
					    AND HOUR(qs.datetime) > 9
					    GROUP BY HOUR(qs.datetime)
					    ");

					$chart = new VerticalBarChart();
					$chart1 = new VerticalBarChart();

					$dataSet = new XYDataSet();
					$dataSet1 = new XYDataSet();


					    while($row = mysql_fetch_assoc($res124)){
					    $roww = mysql_fetch_assoc($res1244);
					    $data['page']['call_distribution_per_hour'] .= '
					    <tr class="odd">
					    <td>'.$row[datetime].':00</td>
					    <td>'.(($row[answer_count]!='')?$row[answer_count]:"0").'</td>
					    <td>'.(($row[call_answer_pr]!='')?$row[call_answer_pr]:"0").' %</td>
					        <td>'.(($roww[unanswer_count]!='')?$roww[unanswer_count]:"0").'</td>
					        <td>'.(($roww[call_unanswer_pr]!='')?$roww[call_unanswer_pr]:"0").'%</td>
						<td>'.(($row[avg_durat]!='')?$row[avg_durat]:"0").' წამი</td>
						    <td>'.(($row[avg_hold]!='')?$row[avg_hold]:"0").' წამი</td>
						        <td></td>
						        <td></td>
						        </tr>
						        ';
					$dataSet->addPoint(new Point($row[datetime].':00', ($row[answer_count]!='')?$row[answer_count]:"0"));
					$dataSet1->addPoint(new Point($row[datetime].':00', ($roww[unanswer_count]!='')?$roww[unanswer_count]:"0"));

	}
	$chart->setDataSet($dataSet);
	$chart1->setDataSet($dataSet1);
	$chart->setTitle("ნაპასუხები ზარები საათების  მიხედვით");
	$chart1->setTitle("უპასუხო ზარები საათების მიხედვით");
	$chart->render("generated/answer_call_per_time.png");
	$chart1->render("generated/unanswer_call_per_time.png");


						        //-------------------------------------------------


//------------------------------ ზარის განაწილება კვირების მიხედვით


$res12 = mysql_query("
					SELECT  CASE
									WHEN DAYOFWEEK(qs.datetime) = 1 THEN 'კვირა'
					WHEN DAYOFWEEK(qs.datetime) = 2 THEN 'ორშაბათი'
					WHEN DAYOFWEEK(qs.datetime) = 3 THEN 'სამშაბათი'
					WHEN DAYOFWEEK(qs.datetime) = 4 THEN 'ოთხშაბათი'
					WHEN DAYOFWEEK(qs.datetime) = 5 THEN 'ხუთშაბათი'
					WHEN DAYOFWEEK(qs.datetime) = 6 THEN 'პარასკევი'
					WHEN DAYOFWEEK(qs.datetime) = 7 THEN 'შაბათი'
					END AS `datetime`,
					COUNT(*) AS `answer_count`,
					ROUND((( COUNT(*) / (
					SELECT COUNT(*) AS `count`
					FROM 	queue_stats AS qs,
					qname AS q,
					qagent AS ag,
					qevent AS ac
					WHERE qs.qname = q.qname_id
					AND qs.qagent = ag.agent_id
					AND qs.qevent = ac.event_id
					AND DATE(qs.datetime) >= '$start_time'
					AND DATE(qs.datetime) <= '$end_time'
					AND q.queue IN ($queue,'NONE')
					AND ac.event IN ('COMPLETECALLER','COMPLETEAGENT')
					)) *100),2) AS `call_answer_pr`,
					ROUND((SUM(qs.info2) / COUNT(*)),0) AS `avg_durat`,
					ROUND((SUM(qs.info1) / COUNT(*)),0) AS `avg_hold`
					FROM 	queue_stats AS qs,
					qname AS q,
					qagent AS ag,
					qevent AS ac
					WHERE qs.qname = q.qname_id
					AND qs.qagent = ag.agent_id
					AND qs.qevent = ac.event_id
					AND DATE(qs.datetime) >= '$start_time'
					AND DATE(qs.datetime) <= '$end_time'
					AND q.queue IN ($queue,'NONE')
					AND ac.event IN ('COMPLETECALLER','COMPLETEAGENT')
					GROUP BY DAYOFWEEK(qs.datetime)
					");

					$res122 = mysql_query("
					SELECT
					COUNT(*) AS `unanswer_count`,
					ROUND((( COUNT(*) / (
					SELECT COUNT(*) AS `count`
					FROM 	queue_stats AS qs,
					qname AS q,
					qagent AS ag,
					qevent AS ac
					WHERE qs.qname = q.qname_id
					AND qs.qagent = ag.agent_id
					AND qs.qevent = ac.event_id
					AND DATE(qs.datetime) >= '$start_time'
					AND DATE(qs.datetime) <= '$end_time'
					AND q.queue IN ($queue,'NONE')
					AND ac.event IN ('ABANDON','EXITWITHTIMEOUT')
					)) *100),2) AS `call_unanswer_pr`
					FROM 	queue_stats AS qs,
					qname AS q,
					qagent AS ag,
					qevent AS ac
					WHERE qs.qname = q.qname_id
					AND qs.qagent = ag.agent_id
					AND qs.qevent = ac.event_id
					AND DATE(qs.datetime) >= '$start_time'
					AND DATE(qs.datetime) <= '$end_time'
					AND q.queue IN ($queue,'NONE')
					AND ac.event IN ('ABANDON','EXITWITHTIMEOUT')
					GROUP BY DAYOFWEEK(qs.datetime)
					");
				$chart = new VerticalBarChart();
				$chart1 = new VerticalBarChart();

				$dataSet = new XYDataSet();
				$dataSet1 = new XYDataSet();

					while($row = mysql_fetch_assoc($res12)){
					$roww = mysql_fetch_assoc($res122);
					$data['page']['call_distribution_per_day_of_week'] .= '

					<tr class="odd">
					<td>'.$row[datetime].'</td>
					<td>'.(($row[answer_count]!='')?$row[answer_count]:"0").'</td>
					    <td>'.(($row[call_answer_pr]!='')?$row[call_answer_pr]:"0").' %</td>
					    <td>'.(($roww[unanswer_count]!='')?$roww[unanswer_count]:"0").'</td>
					        <td>'.(($roww[call_unanswer_pr]!='')?$roww[call_unanswer_pr]:"0").'%</td>
					<td>'.(($row[avg_durat]!='')?$row[avg_durat]:"0").' წამი</td>
					    <td>'.(($row[avg_hold]!='')?$row[avg_hold]:"0").' წამი</td>
					        <td></td>
					        <td></td>
					        </tr>
					        ';

					$dataSet->addPoint(new Point($row[datetime], (($row[answer_count]!='')?$row[answer_count]:"0")));
					$dataSet1->addPoint(new Point($row[datetime], (($roww[unanswer_count]!='')?$roww[unanswer_count]:"0")));

	}
	$chart->setDataSet($dataSet);
	$chart1->setDataSet($dataSet1);
	$chart->setTitle("ნაპასუხები ზარები კვირის დღეების  მიხედვით");
	$chart1->setTitle("უპასუხო ზარები კვირის დღეების მიხედვით");
	$chart->render("generated/answer_call_per_week.png");
	$chart1->render("generated/unanswer_call_per_week.png");

					        //---------------------------------------------------
}


//echo json_encode($data);
//return 0;


?>
    <head>
    <script type="text/javascript" language="javascript" src="../../js/jquery-1.9.1.min.js"></script>	
	<script type="text/javascript" language="javascript" src="../../js/jquery-ui-1.10.3.custom.min.js"></script>	
	<script type="text/javascript" src="js/jNotify.jquery.min.js"></script>
	
    <script type="text/javascript">
    $(document).ready(function () {        
        window.print();
    });
    
    </script>
    	<style type="text/css">
		caption{
		    margin: 0;
			padding: 0;
			background: #f3f3f3;
			height: 40px;
			line-height: 40px;
			text-indent: 2px;
			font-family: "Trebuchet MS", Trebuchet, Arial, sans-serif;
			font-size: 140%;
			font-weight: bold;
			color: #000;
			text-align: left;
			letter-spacing: 1px;
			border-top: dashed 1px #c2c2c2;
			border-bottom: dashed 1px #c2c2c2;
		}
		div, caption, td, th, h2, h3, h4 {
			font-size: 12px;
			font-family: verdana,sans-serif;
			voice-family: "\"}\"";
			voice-family: inherit;
			color: #333;
		}
		tbody {
			display: table-row-group;
			vertical-align: middle;
			border-color: inherit;
		}
		tbody tr {
			background: #dfedf3;
			font-size: 110%;
		}
		tr {
			display: table-row;
			vertical-align: inherit;
			border-color: inherit;
		}
		tbody tr th, tbody tr td {
			padding: 5px;
			border: solid 1px #326e87;
			text-align: center;
			vertical-align:middle;
		}
		thead tr th {
			height: 32px;
			aline-height: 32px;
			text-align: center;
			vertical-align:middle;
			color: #1c5d79;
			background: #CBDFEE;
			border-left: solid 1px #FF9900;
			border-right: solid 1px #FF9900;
			border-collapse: collapse;
		}
		table.sortable a.sortheader {
			text-decoration: none;
			display: block;
			color: #1c5d79;
			xcolor: #000000;
			font-weight: bold;
		}
		a{
			cursor: pointer;
		}
		.tdstyle{
			text-align: left;
			vertical-align:middle;
		}
	table {
	width: 100%;
}
 .breakhere {
            page-break-inside : avoid;
 	        width: 19cm;
         	text-align: center;
         /*	border:solid; */
         	margin: auto;
    }
    </style>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
<body >
<div class="breakhere">
<?php  if (strpos($report_name,'ტექნიკური ინფო')>0) {

?>
  <table width="100%" border="0" cellpadding="0" cellspacing="0" style="margin-top: 50px">
    <caption>ტექნიკური ინფო</caption>
    <tr>
    	<th></th>
        <th>სულ</th>
        <th>ნაპასუხები</th>
        <th>უპასუხო</th>
        <th>დამუშავებული *</th>
        <th>ნაპასუხებია</th>
        <th>უპასუხოა</th>
        <th>დამუშავებულია</th>
    </tr>
    <tr id="technik_info">
<?php echo $data['page']['technik_info'] ?>
    </tr>
    </table>

    <div id="chart_container0" style="float:left; width: 50%; height: 300px;">
    <img  src="generated/technical_info1.png">
    </div>
    <div id="chart_container0r" style="float:left; width: 50%; height: 300px;">
    <img  src="generated/technical_info2.png">
    </div>
       	</div>
 <div class="breakhere" style="page-break-before: always;" >
	<table >
<tr><td valign="top" width="50%" style="padding:0 5px 0 0;">
          <table >
                <caption>რეპორტ ინფო</caption>
                <?php  echo $data['page']['report_info'] ;?>
           </table>
        </td><td valign="top" width="50%">
              <table >
                <caption>ნაპასუხები ზარები</caption>
                 <?php echo $data['page']['answer_call_info']; ?>
              </table>
            </td>
        </tr>
    </table>
     <br>
  
<?php
};
if (strpos($report_name,'ნაპასუხები ზარები ოპერატორების მიხედვით')>0) {
    ;
;?>
 <!-- ----------------------------------------------------------------------------------------------------- -->
    <table>
        <caption>ნაპასუხები ზარები ოპერატორების მიხედვით</caption>
            <tr>
                  <th>ოპერატორი</th>
                  <th>ზარები</th>
                  <th>% ზარები</th>
                  <th>ზარის დრო</th>
                  <th>% ზარის დრო</th>
                  <th>საშ. ზარის ხანგძლივობა</th>
                  <th>ლოდინის დრო</th>
                  <th>საშ. ლოდისნის ხანგძლივობა</th>
            </tr>
         <?php echo  $data['page']['answer_call_by_queue'] ?>
    </table>
    <br>
    <img  src="generated/answer_call_by_queue.png" style='width: 20cm;'/>
</div>
<?php
};
if (strpos($report_name,'მომსახურების დონე(Service Level)')>0) {
    ;
;?>
<div class="breakhere">
 <table >
        <caption>მომსახურების დონე(Service Level)</caption>
          <tr>
                    <th>პასუხი</th>
                    <th>რაოდენობა</th>
                    <th>დელტა</th>
                    <th>%</th>
          </tr>
         <?php echo $data['page']['service_level']?>
    </table>
    <img alt="Vertical bars chart" src="generated/service_level.png"/>
    <?php
};
if (strpos($report_name,'ნაპასუხები ზარები რიგის მიხედვით')>0) {
    ;
;?>
    <table >
        <caption>ნაპასუხები ზარები რიგის მიხედვით</caption>
        <tr>
           <th>რიგი</th>
           <th>სულ</th>
           <th>%</th>
        </tr>
    <?php echo $data['page']['answer_call']?>
   </table>
    <br>
    <img  src="generated/answer_call.png"/>'
</div>
<?php
};
if (strpos($report_name,'კავშირის გაწყვეტის მიზეზი')>0) {
    ?>
<div class="breakhere">
    <table >
        <caption>კავშირის გაწყვეტის მიზეზი</caption>
            <tr>
                <th>მიზეზი</th>
                <th>სულ</th>
                <th>სულ</th>
            </tr>
        <?php echo $data['page']['disconnection_cause'] ;?>
    </table>
    <br>
    <img  src="generated/disconnection_cause.png"/>'
        <?php
};
if (strpos($report_name,'კავშირის გაწყვეტის მიზეზი (უპასუხო)')>0) {
    ?>
 </div>
      
 <div class="breakhere" style="page-break-before: always;" >
	<table>
	   <tr>
			<td valign="top" width="50%" style="padding: 0 5px 0 0;">
				<table>
				<caption>რეპორტ ინფო</caption>
                <?php  echo $data['page']['report_info'] ;?>
				</table>
			</td>
			<td valign="top" width="50%">
				<table>
				<caption>უპასუხო ზარები</caption>
                <?php echo $data['page']['unanswer_call'];  ?>
	          </table>
			</td>
		</tr>
	</table>
	<br>
	<table>
	   <caption>კავშირის გაწყვეტის მიზეზი (უპასუხო)</caption>
	   <tr>
    		<th>მიზეზი</th>
    		<th>სულ</th>
    		<th>%</th>
		</tr>
            <?php echo $data['page']['disconnection_cause_unanswer'];?>
	</table>
    <img alt="Vertical bars chart" src="generated/disconnection_cause_unanswer.png"/>
    </div>
    
            <?php
};
if (strpos($report_name,'უპასუხო ზარები რიგის მიხედვით')>0) {
    ?>
    
 	<div class="breakhere">
	<table>
		<caption>უპასუხო ზარები რიგის მიხედვით</caption>
        <tr>
		   	<th>რიგი</th>
			<th>სულ</th>
			<th>%</th>
        </tr>
	   <?php echo	$data['page']['unanswered_calls_by_queue'] ?>
    </table>
    <img src="generated/unanswered_calls_by_queue.png">
 </div>
 <?php
};
if (strpos($report_name,'ზარის განაწილება დღეების მიხედვით')>0) {
    ?>
 <div class="breakhere" style="page-break-before: always;" >
	<table >
		<caption>ზარის განაწილება დღეების მიხედვით</caption>
		<tr>
			<th>თარირი</th>
			<th>ნაპასუხები</th>
			<th>% ნაპასუხები</th>
			<th>უპასუხო</th>
			<th>% უპასუხო</th>
			<th>საშ. ხანგძლივობა</th>
			<th>საშ. ლოდინის ხანგძლივობა</th>
			<th>შესვლა</th>
			<th>გასვლა</th>
		</tr>
		<?php echo $data['page']['call_distribution_per_day'];  ?>
	</table>
</div>
<div class="breakhere">
	<img src="generated/answer_call_per_day.png" />
    <img  src="generated/unanswer_call_per_day.png" />
</div>
 <?php
};
if (strpos($report_name,'ზარის განაწილება საათების მიხედვით')>0) {
    ?>
<div class="breakhere">
	<table>
		<caption>ზარის განაწილება საათების მიხედვით</caption>
        <tr>
            <th>საათი</th>
            <th>ნაპასუხები</th>
            <th>% ნაპასუხები</th>
            <th>უპასუხო</th>
            <th>% უპასუხო</th>
            <th>საშ. ხანგძლივობა</th>
            <th>საშ. ლოდინის ხანგძლივობა</th>
            <th>შესვლა</th>
            <th>გასვლა</th>
	   </tr>
        <?php echo $data['page']['call_distribution_per_hour'] ?>
	</table>
	<img alt="" src="generated/answer_call_per_time.png">
	<img alt="" src="generated/unanswer_call_per_time.png">
</div>
 <?php
};
if (strpos($report_name,'ზარის განაწილება კვირის დღეების მიხედვით')>0) {
    ?>
<div class="breakhere">
	<table>
		<caption>ზარის განაწილება კვირის დღეების მიხედვით</caption>
		<tr>
            <th>დღე</th>
            <th>ნაპასუხები</th>
            <th>% ნაპასუხები</th>
            <th>უპასუხო</th>
            <th>% უპასუხო</th>
            <th>საშ. ხანგძლივობა</th>
            <th>საშ. ლოდინის ხანგძლივობა</th>
            <th>შესვლა</th>
            <th>გასვლა</th>
		</tr>
        <?php echo $data['page']['call_distribution_per_day_of_week'] ?>
	</table>
	<br>
	<img alt="" src="generated/answer_call_per_week.png">
	<img alt="" src="generated/unanswer_call_per_week.png">
</div>
 <?php
};
if (strpos($report_name,'შემოსული ზარები ტიპების მიხედვით')>0) {
    ?>
 	<div class="breakhere">
	<table>
		<caption>შემოსული ზარები ტიპების მიხედვით</caption>
        <tr>
		   	<th>დასახელება</th>
			<th>რაოდენობა</th>
			<th>%</th>
        </tr>
	   <?php echo	$data['page']['by_type'] ?>
    </table>
    <img src="generated/by_type.png">
 </div>
  <?php
};
if (strpos($report_name,'შემოსული  ინფორმაცია  ქვე-კატეგორიების  მიხედვით')>0) {
    ?>
<div class="breakhere">
	<table>
		<caption>შემოსული  ინფორმაცია  ქვე-კატეგორიების  მიხედვით</caption>
        <tr>
		   	<th>დასახელება</th>
			<th>რაოდენობა</th>
			<th>%</th>
        </tr>
	   <?php echo	$data['page']['by_category'] ?>
    </table>
    <img src="generated/by_category.png">
 </div>
   <?php
};
if (strpos($report_name,'შემოსული  პრეტენზია  ქვე-კატეგორიების  მიხედვით')>0) {
    ?>
 <div class="breakhere">
	<table>
		<caption>შემოსული  პრეტენზია  ქვე-კატეგორიების  მიხედვით</caption>
        <tr>
		   	<th>დასახელება</th>
			<th>რაოდენობა</th>
			<th>%</th>
        </tr>
	   <?php echo	$data['page']['pr_by_category'] ?>
    </table>
    <img src="generated/pr_by_category.png">
 </div> 
   <?php
};
if (strpos($report_name,'ინტერესი პროდუქტის  კატეგორიის  მიხედვით')>0) {
    ?>  
<div class="breakhere" style="page-break-before: always;">
	<table>
		<caption>ინტერესი პროდუქტის  კატეგორიის  მიხედვით</caption>
        <tr>
		   	<th>დასახელება</th>
			<th>რაოდენობა</th>
			<th>%</th>
        </tr>
	   <?php echo	$data['page']['i_by_p_category'] ?>
    </table>
    <img src="generated/i_by_p_category.png">
 </div>
    <?php
};
if (strpos($report_name,'ინტერესი ბრენდების  მიხედვით')>0) {
    ?>  
 <div class=class="breakhere" style="page-break-before: always;">
	<table>
		<caption>ინტერესი ბრენდების  მიხედვით</caption>
        <tr>
		   	<th>დასახელება</th>
			<th>რაოდენობა</th>
			<th>%</th>
        </tr>
	   <?php echo	$data['page']['i_by_brend'] ?>
    </table>
    <img src="generated/i_by_brend.png">
 </div> 
    <?php
};
if (strpos($report_name,'პრეტენზიები პროდუქტების კატეგორიის  მიხედვით')>0) {
    ?>
 <div class="breakhere">
	<table>
		<caption>პრეტენზიები პროდუქტების კატეგორიის  მიხედვით</caption>
        <tr>
		   	<th>დასახელება</th>
			<th>რაოდენობა</th>
			<th>%</th>
        </tr>
	   <?php echo	$data['page']['p_by_category'] ?>
    </table>
    <img src="generated/p_by_category.png">
 </div> 
     <?php
};
if (strpos($report_name,'პრეტენზიები ბრენდის  მიხედვით')>0) {
    ?>
    <div class="breakhere">
	<table>
		<caption>პრეტენზიები ბრენდის  მიხედვით</caption>
        <tr>
		   	<th>დასახელება</th>
			<th>რაოდენობა</th>
			<th>%</th>
        </tr>
	   <?php echo	$data['page']['p_by_brend'] ?>
    </table>
    <img src="generated/p_by_brend.png">
 </div> 
</body>
<?}